package com.logistics.team3.web.action;

import java.lang.reflect.ParameterizedType;
import java.util.Map;

import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class BaseAction<T> extends ActionSupport implements RequestAware,SessionAware,ApplicationAware,ModelDriven<T> {

	private static final long serialVersionUID = 2561334129719481263L;
	protected T model;
	protected  Map<String, Object> request;
	protected  Map<String, Object> session;
	protected  Map<String, Object> application;
	@SuppressWarnings("unchecked")
	public BaseAction() {
		ParameterizedType type=(ParameterizedType)this.getClass().getGenericSuperclass();
		Class<?> clazz=(Class<?>)type.getActualTypeArguments()[0];
		try {
			model=(T) clazz.newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	@Override
	public T getModel() {
		return model;
	}

	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public void setApplication(Map<String, Object> application) {
		this.application = application;
	}

}
